package com.cfec.educationplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfec.educationplatform.domain.TbAichatHistory;
import com.cfec.educationplatform.service.TbAichatHistoryService;
import com.cfec.educationplatform.mapper.TbAichatHistoryMapper;
import com.cfec.educationplatform.util.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author diyu
* @description 针对表【tb_aichat_history(存储和大模型的对话)】的数据库操作Service实现
* @createDate 2025-04-20 10:21:42
*/
@Service
public class TbAichatHistoryServiceImpl extends ServiceImpl<TbAichatHistoryMapper, TbAichatHistory>
    implements TbAichatHistoryService{

    @Resource(name = "tbAichatHistoryMapper")
    private TbAichatHistoryMapper tbAichatHistoryMapper;

    @Override
    public ResultData<Object> GetHistory(Long userId) {
        try {
            QueryWrapper<TbAichatHistory> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("user_id", userId)
                    .eq("history_state", "1");
            List<TbAichatHistory> tbAichatHistories = tbAichatHistoryMapper.selectList(queryWrapper);
            if (!tbAichatHistories.isEmpty()) {
                return new ResultData<>(200, "查询成功", tbAichatHistories);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new ResultData<>(500, "查询失败", null);
    }
}




